#import "CustomWindow.h"
#import <AppKit/AppKit.h>

@implementation CustomWindow

- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag
{
    NSWindow* result = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
	
    [result setLevel: NSStatusWindowLevel];
    [result setHasShadow:NO];
	
	[self setContentSize:NSMakeSize(35, 21)];
	
	{
		NSScreen *screen = [NSScreen mainScreen];
		NSRect	 frame = [screen frame];
		
		frame.origin.y = frame.size.height - 21;
		frame.origin.x = frame.size.width / 2 - 17.5;
		
		[self setFrameOrigin:frame.origin];
		
		frame = [screen frame];
	}
	
    return result;
}

- (void)mouseDown:(NSEvent *)theEvent
{  
	NSEvent	*event = nil;
	NSPoint	newLocation = NSMakePoint(0, -4);
	
	event = [NSEvent  mouseEventWithType:[theEvent type]
						location:newLocation
						modifierFlags:[theEvent modifierFlags]
						timestamp:[theEvent timestamp]
						windowNumber:[theEvent windowNumber]
						context:nil	//(NSGraphicsContext*)context
						eventNumber:[event eventNumber]
						clickCount:[event clickCount]
						pressure:[event pressure]];

	[myMenu setAutoenablesItems:NO];
	[myView setIsSelected:YES];
	[NSMenu popUpContextMenu:myMenu withEvent:event forView:[self contentView]];
	[myView setIsSelected:NO];
}

- (IBAction)openSystemPreferences:(id)sender
{
	NSWorkspace *ws = [NSWorkspace sharedWorkspace];
	
	[ws launchApplication:@"System Preferences"];
}

@end
